package com.idfsgm;

import java.util.Date;

import com.example.idfsgm.R;

import datatypes.DutyDate;
import datatypes.GuardDuty;
import datatypes.Soldier;
import datatypes.Team;

import Utils.SavingAndLoadingCenter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class ServiceOpener extends Activity {
	private ListView dutyHourList;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.service_opener);

		
		dutyHourList = (ListView) findViewById(R.id.duty_hours);
		dutyHourList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

		int dutyType = SharedPref.GuardDuty;
		String[] hourArray = buildHourArray(
				SavingAndLoadingCenter.loadDutyLimitHours(dutyType), dutyType);
/*
		dutyHourList.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_multiple_choice, hourArray));
        */
	}

	public String[] buildHourArray(DutyDate date, int dutyType) {

		String[] hourArray;
		int index = 0;
		int hourDifferential = 2;
		Date startingDate = date.getStartingDate();
		Date endingDate = date.getEndingDate();

		long val = endingDate.getTime() - startingDate.getTime();
		int arraySize =  (int) val;
		hourArray = new String[arraySize];
		while (startingDate.after(endingDate)) {
			hourArray[index++] = startingDate.getHours() + " : "
					+ startingDate.getMinutes() + endingDate.getHours() + " : "
					+ endingDate.getMinutes();
			startingDate.setHours(startingDate.getHours() + hourDifferential);
		}

		if (!startingDate.equals(endingDate)) {
			startingDate.setHours(startingDate.getHours() - hourDifferential);
			hourArray[index++] = startingDate.getHours() + " : "
					+ startingDate.getMinutes() + endingDate.getHours() + " : "
					+ endingDate.getMinutes();
		}

		return hourArray;

	}
}